package md.rdcrng.test;

import java.util.logging.Level;
import java.util.logging.Logger;
import javax.faces.component.UIComponent;
import javax.faces.context.FacesContext;
import javax.faces.convert.Converter;
import javax.faces.convert.FacesConverter;
import javax.inject.Inject;

/**
 <p/>
 @author Radu Creanga <rdcrng@gmail.com>
 */
@FacesConverter(forClass = String.class)
public class TypedTestConverter implements Converter {

    private static final Logger LOG = Logger.getLogger(TypedTestConverter.class.getName());
    @Inject private Test test;

    @Override
    public Object getAsObject(FacesContext context, UIComponent component, String value) {
        // should get a NPE if injection doesn't happen
        TypedTestConverter.LOG.log(Level.INFO, "{0}#getAsObject({1})",
                new String[] {TypedTestConverter.class.getName(), this.test.getName()});
        return value;
    }

    @Override
    public String getAsString(FacesContext context, UIComponent component, Object value) {
        // should get a NPE if injection doesn't happen
        TypedTestConverter.LOG.log(Level.INFO, "{0}#getAsString({1})",
                new String[] {TypedTestConverter.class.getName(), this.test.getName()});
        return value.toString();
    }

}
